<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI分析图表测试页面</title>
    <style>
        body {
            font-family: "Microsoft YaHei", Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background: #f5f5f5;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        
        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
        }
        
        .chart-row {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }
        
        .chart-container {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        
        .chart-box {
            width: 100%;
            height: 400px;
            border: 1px solid #eee;
            border-radius: 4px;
        }
        
        .btn {
            background: #667eea;
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            display: block;
            margin: 0 auto 30px;
        }
        
        .btn:hover {
            background: #5a67d8;
        }
        
        .status {
            text-align: center;
            padding: 10px;
            margin-bottom: 20px;
            border-radius: 4px;
        }
        
        .status.loading {
            background: #fff3cd;
            color: #856404;
        }
        
        .status.success {
            background: #d4edda;
            color: #155724;
        }
        
        .status.error {
            background: #f8d7da;
            color: #721c24;
        }
    </style>
    
    <!-- 引入ECharts -->
    <script src="./admin/components/echarts/echarts.min.js"></script>
    <!-- 引入修复脚本 -->
    <script src="./static/js/ai-analysis-fix.js"></script>
</head>
<body>
    <div class="container">
        <h1>🎬 AI分析图表测试页面</h1>
        
        <button class="btn" onclick="loadAIAnalysis()">加载AI分析数据</button>
        
        <div id="status" class="status" style="display: none;"></div>
        
        <div class="chart-row">
            <div class="chart-container">
                <h3>评分分布</h3>
                <div id="rating-chart" class="chart-box"></div>
            </div>
            
            <div class="chart-container">
                <h3>年份趋势</h3>
                <div id="year-chart" class="chart-box"></div>
            </div>
        </div>
        
        <div class="chart-row">
            <div class="chart-container">
                <h3>ROC曲线对比</h3>
                <div id="roc-chart" class="chart-box"></div>
            </div>
            
            <div class="chart-container">
                <h3>混淆矩阵</h3>
                <div id="confusion-chart" class="chart-box"></div>
            </div>
        </div>
        
        <div class="chart-row">
            <div class="chart-container">
                <h3>特征相关性</h3>
                <div id="correlation-chart" class="chart-box"></div>
            </div>
        </div>
    </div>
    
    <script>
        function showStatus(message, type) {
            const status = document.getElementById('status');
            status.textContent = message;
            status.className = 'status ' + type;
            status.style.display = 'block';
        }
        
        async function loadAIAnalysis() {
            showStatus('正在加载AI分析数据...', 'loading');
            
            try {
                const response = await fetch('/api/admin/analysis/ai');
                
                if (!response.ok) {
                    throw new Error('HTTP错误: ' + response.status);
                }
                
                const data = await response.json();
                console.log('AI分析数据:', data);
                
                showStatus('数据加载成功,正在绘制图表...', 'success');
                
                // 使用修复脚本绘制图表
                if (window.AI_ANALYSIS_CHART_FIXER) {
                    window.AI_ANALYSIS_CHART_FIXER.drawRatingDistribution('rating-chart', data);
                    window.AI_ANALYSIS_CHART_FIXER.drawYearTrend('year-chart', data);
                    window.AI_ANALYSIS_CHART_FIXER.drawROCCurves('roc-chart', data);
                    window.AI_ANALYSIS_CHART_FIXER.drawConfusionMatrix('confusion-chart', data);
                    window.AI_ANALYSIS_CHART_FIXER.drawCorrelationMatrix('correlation-chart', data);
                    
                    setTimeout(() => {
                        showStatus('✓ 所有图表加载完成!', 'success');
                    }, 500);
                } else {
                    throw new Error('图表修复脚本未加载');
                }
                
            } catch (error) {
                console.error('加载失败:', error);
                showStatus('✗ 加载失败: ' + error.message, 'error');
            }
        }
        
        // 页面加载时自动执行
        window.addEventListener('DOMContentLoaded', function() {
            console.log('页面已加载');
            console.log('ECharts可用:', typeof echarts !== 'undefined');
            console.log('修复脚本可用:', typeof window.AI_ANALYSIS_CHART_FIXER !== 'undefined');
        });
    </script>
</body>
</html>
